Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6236] fix(core): fix possible resource leak in BaseCatalog #6253

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Abyss-lord
Copy link
Contributor

What changes were proposed in this pull request?

Use try-with-resource to fix possible resource leak in BaseCatalog.

Why are the changes needed?

Fix: #6236

Does this PR introduce any user-facing change?

No.

How was this patch tested?

local test.

@Abyss-lord
Copy link
Contributor Author

@justinmclean @tengqm ,could you please review this PR when you have time? I’d really appreciate your feedback.

@jerryshao
Copy link
Contributor

@xunliu @jerqi can you please help to review?

@jerryshao jerryshao requested review from xunliu and jerqi January 15, 2025 11:25
BaseAuthorization<?> authorization =
BaseAuthorization.createAuthorization(classLoader, authorizationProvider);

try (BaseAuthorization<?> authorization =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the authorization be closed after creating plugin? Do we need close method? cc @xunliu

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is ok.

Another question is:

Should the authorization be closed after creating plugin? Do we need close method? cc @xunliu

We already closed the authorization plugin in the core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java#L229

  @Override
  public void close() throws IOException {
    if (ops != null) {
      ops.close();
      ops = null;
    }
    if (authorizationPlugin != null) {
      authorizationPlugin.close();
      authorizationPlugin = null;
    }
    if (catalogCredentialManager != null) {
      catalogCredentialManager.close();
      catalogCredentialManager = null;
    }
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, Authorization class is similar to a factory class. It's weird that the factory class has close method.

@jerryshao
Copy link
Contributor

@jerqi @xunliu can you please review again to see if it is a necessary fix?

@jerryshao jerryshao requested a review from jerqi January 22, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Possible resource leak in BaseCatalog.java
4 participants